<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>作业2</title>
    <style>
        div {
            position: absolute;
            width: 10px;
            height: 10px;
            background-color: #F00;
        }
    </style>
</head>

<body>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <script>
        document.onmousemove = function(e) { //给整个文档绑定事件鼠标移动事件.
            var e = e || window.event;
            var divs = document.querySelectorAll('div'); //获取所有的div
            for (var i = divs.length - 1; i > 0; i--) { //循环所有div 倒着循环
                divs[i].style.left = (parseInt(divs[i - 1].style.left)) + 'px'; //后一个的位移是前一个的位移
                divs[i].style.top = (parseInt(divs[i - 1].style.top)) + 'px'; //后一个的位移是前一个的位移
            }
            divs[0].style.left = e.clientX + "px";
            divs[0].style.top = e.clientY + "px";

            //通过style属性获取/设置的属性的距离/宽度 单位都是px
        }
    </script>
</body>

</html>